<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :keyboard="false"
    v-bind:prefixNo="prefixNo"
    switchHelp
    switchFullscreen
    @ok="handleOk"
    okText="保存"
    @cancel="handleCancel"
    wrapClassName="ant-modal-cust-warp"
    :id="prefixNo"
    style="top:5%;height: 110%;overflow-y: hidden">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :lg="6" :md="12" :sm="24">
            <!-- <a-form-item  label="渠道来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input placeholder="请输入渠道来源" v-decorator.trim="[ 'source', validatorRules.source]"/>
            </a-form-item> -->
            <a-form-item label="渠道来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
             <a-select placeholder="请输入渠道来源" :disabled="isNoCredit" v-decorator.trim="[ 'source', validatorRules.source]"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
               <a-select-option v-for="(item,index) in sourceList" :key="index" :value="item.name" >{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="客户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-input placeholder="请输入客户姓名" :disabled="isNoCredit" v-decorator.trim="[ 'name', validatorRules.name]" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="身份证号码" :labelCol="labelCol" :wrapperCol="wrapperCol" style="position: relative;">
              <a-input placeholder="请输入身份证号码" :maxLength="18" v-decorator.trim="[ 'idNumber', validatorRules.idNumber]" @change="getCredit"/>
              <a-tag style="position: absolute;top:50%;transform: translate(20%,-50%);" v-show="credit.show" :color="credit.color">{{ credit.text }}</a-tag>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="联系号码" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-input placeholder="请输入联系号码" :disabled="isNoCredit" :maxLength="11" v-decorator.trim="[ 'tel', validatorRules.tel]" />
            </a-form-item>                        
          </a-col>
          
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="门店名称" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-select placeholder="请输入门店名称" :disabled="isNoCredit" v-decorator.trim="[ 'storeName', validatorRules.storeName]"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
                <a-select-option v-for="(item,index) in storeNameList" :key="index" :value="item" >{{ item }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-input placeholder="请输入地址"  :disabled="isNoCredit" v-decorator.trim="[ 'address', validatorRules.address]"/>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="业务员" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select placeholder="请输入业务员" :disabled="isNoCredit" v-decorator.trim="[ 'ope', validatorRules.ope]"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
               <a-select-option v-for="(item,index) in opeList" :key="index" :value="item.name" >{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item label="开单时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请输入开单时间" :disabled="isNoCredit" v-model="model.startTime" v-decorator.trim="[ 'startTime', validatorRules.startTime]" ></j-date>
        </a-form-item>
      </a-col>
      
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="业务类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select placeholder="请输入业务类型" :disabled="isNoCredit" v-decorator.trim="[ 'type', validatorRules.type]"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children"  @change="changeType">
               <a-select-option v-for="(item,index) in typeList" :key="index" :value="item.name" >{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- <a-col :lg="8" :md="12" :sm="24" v-show="model.type === '回收'">
            <a-form-item label="出货价/还款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-input placeholder="请输入出货价/还款金额" v-model="model.deliveryPrice" v-decorator.trim="[ 'deliveryPrice', validatorRules.deliveryPrice]"/>
            </a-form-item>
          </a-col> -->
        </a-row>
        <j-editable-table id="deliveryModal"
          :ref="refKeys[0]"
          :loading="materialTable.loading"
          :columns="materialTable.columns"
          :dataSource="materialTable.dataSource"
          :maxHeight="300"
          :rowNumber="false"
          :rowSelection="true"
          :actionButton="true"
          :dragSort="true"
          @valueChange="onValueChange"
          @deleted="onDeleted"
          :disabled="isNoCredit"
          >
          <!-- @valueChange="onValueChange" -->
        </j-editable-table>
    
          <!-- no show -->
        <a-row class="form-row" :gutter="24" style="margin-top: 30px;">
          <a-col :lg="8" :md="12" :sm="24" v-show="model.type !== '回收'">
            <a-form-item label="寄存时长服务费率" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-select placeholder="请输入寄存时长服务费率" :disabled="isNoCredit" @change="ChangeRate" v-model="model.rate"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
                <a-select-option v-for="(item,index) in rateList" :key="index" :value="item" >{{ item }}</a-select-option>
          </a-select>
            </a-form-item>
          </a-col>
          <!-- no show -->
          <a-col :lg="6" :md="12" :sm="24" v-show="model.type !== '回收'">
            <a-form-item label="收益" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input placeholder="请输入收益" :disabled="isNoCredit" :read-only="rate.index < 3" v-model="model.profit"/>
              <!-- <a-input placeholder="请输入收益" :read-only="true" v-model="profit" v-decorator.trim="[ 'profit', validatorRules.profit]"/> -->
            </a-form-item>
          </a-col>
          <!-- no show -->
          <a-col :lg="10" :md="12" :sm="24" v-show="model.type !== '回收'">
            <a-form-item label="寄存到期时间记录/出货时间" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <j-date dateFormat="YYYY-MM-DD" :disabled="isNoCredit" :read-only="rate.index < 3" v-model="model.endTime"></j-date>
              <!-- <j-date dateFormat="YYYY-MM-DD" :read-only="true" v-model="time.Delivery" v-decorator.trim="[ 'endTime', validatorRules.endTime]"></j-date> -->
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="11" :md="12" :sm="24">
            <a-form-item label="到期提醒" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-textarea :rows="7" :disabled="isNoCredit" placeholder="请输入到期提醒" v-decorator.trim="[ 'reminder', validatorRules.reminder]" />
            </a-form-item>
          </a-col>
          <a-col :lg="11" :md="12" :sm="24">
            <a-form-item label="其他备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea :rows="7" :disabled="isNoCredit" placeholder="请输入其他备注" v-decorator.trim="[ 'remark', validatorRules.remark]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="15" :md="12" :sm="24">
             <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="业务图片">
               <j-image-upload v-model="fileList" :disabled="isNoCredit" v-decorator.trim="[ 'fileName', validatorRules.fileName]" bizPath="business" text="上传" isMultiple></j-image-upload>
             </a-form-item>
           </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="15" :md="12" :sm="24">
           <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="业务视频">
              <j-upload v-model="imgName" :disabled="isNoCredit" v-decorator.trim="[ 'imgName', validatorRules.imgName]" bizPath="bill" isMultiple></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="15" :md="12" :sm="24">
            <a-form-item label="行情收益反馈" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-textarea :rows="7" :disabled="isNoCredit" placeholder="请输入其他备注" v-decorator.trim="[ 'feedback', validatorRules.feedback]" />
          </a-form-item>
        </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>
<script>
  import { FormTypes } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import JUpload from '@/components/jeecg/JUpload'
  import JDate from '@/components/jeecg/JDate'
  import JSelectPosition from '@/components/jeecgbiz/JSelectPosition'
  import JImageUpload from '../../../components/jeecg/JImageUpload'
  import { getCustomInfoByNum } from '@/api/api'
  import Vue from 'vue'
  import { BusinessMixin } from '../mixins/BusinessMixin'
import { Modal, notification } from 'ant-design-vue'
  export default {
    name: "BusinessModal",
    mixins: [JEditableTableMixin,BusinessMixin],
    components: {
      JUpload,
      JDate,
      JSelectPosition,
      JImageUpload
    },
    data () {
      return {
        title:"操作",
        width: '1600px',
        isNoCredit:false,
        moreStatus: false,
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        visible: false,
        supList: [],
        deposit:0,
        depotList: [],
        rate:{
          option:[{date:1, rate:3}, {date:10, rate:5}, {date:30, rate:10}],
          currentRate:0,
          index:-1
        },
        columns:{
          other:[
          { title: '物品类型', key: 'category', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options:[],
            validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '物品鉴定级别', key: 'level', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options:[],
            validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '数量', key: 'amount', width: '7%', type: FormTypes.inputNumber,
            validateRules: [{ required: true , message: '${title}不能为空' }]},
            { title: '品牌,规格,重量', key: 'brandWeight', width: '30%', type: FormTypes.input,
              validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '寄存金额', key: 'depositAmount', width: '10%', type: FormTypes.inputNumber,statistics: true,
              validateRules: [{ required: false, message: '${title}不能为空' }]},
            { title: '当日行情价', key: 'daily', width: '10%', type: FormTypes.input,
              validateRules: [{ required: false, message: '${title}不能为空' }]}
          ],
          recycle:[
          { title: '物品类型', key: 'category', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options:[],
            validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '物品鉴定级别', key: 'level', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options:[],
            validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '数量', key: 'amount', width: '7%', type: FormTypes.inputNumber,
            validateRules: [{ required: true , message: '${title}不能为空' }]},
            { title: '品牌,规格,重量', key: 'brandWeight', width: '30%', type: FormTypes.input,
              validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '当日行情价', key: 'daily', width: '10%', type: FormTypes.input,
              validateRules: [{ required: false, message: '${title}不能为空' }]},
            { title: '回收单价', key: 'recyclePrice', width: '10%', type: FormTypes.inputNumber, defaultValue: '', statistics: true,
              validateRules: [{ required: false, message: '${title}不能为空' }]},
              { title: '回收总价', key: 'recycleTotal', width: '10%', type: FormTypes.inputNumber,readonly:true, defaultValue: '0', statistics: true,
              validateRules: [{ required: false, message: '${title}不能为空' }]
            }],
          credit:[
          { title: '寄存金额', key: 'depositAmount', width: '10%', type: FormTypes.inputNumber,statistics: true, readonly:true, defaultValue: '0',
          validateRules: [{ required: false, message: '${title}不能为空' }]}
          ]
        },
        operTimeStr: '',
        prefixNo: 'CGDD',
        sourceList:[],
        opeList:[],
        storeNameList:['沙市玉桥店', '公安一店'],
        typeList:[],
        fileList:[],
        imgName:[],
        credit:{
          text:'',
          color:'',
          show:false
        },
        produceList:[],
        model: {
          startTime:'',
          endTime:'',
          profit:'',
          // deliveryPrice:'',
          rate:'',
          recycleTotal:'',
          type:'',
          amountCount:0
        },
        duration:null,
        engineerId:"",
        rateList:['1天-3%服务费率','10天-5%服务费率','一个月-10%服务费率','综合服务费','过桥5‰每天'],
        // rateList:['1天-3%服务费率','10天-5%服务费率','30天-10%服务费率','综合服务费','过桥5‰每天'],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        refKeys: ['materialDataTable', ],
        tableKeys:['materialDataTable', ],
        activeKey: 'materialDataTable',
        materialTable: {
          loading: false,
          dataSource: [],
          columns: [
            { title: '物品类型', key: 'category', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options:[],
            validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '物品鉴定级别', key: 'level', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options:[],
            validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '数量', key: 'amount', width: '7%', type: FormTypes.inputNumber,
            validateRules: [{ required: true , message: '${title}不能为空' }]},
            { title: '品牌,规格,重量', key: 'brandWeight', width: '30%', type: FormTypes.input,
              validateRules: [{ required: true, message: '${title}不能为空' }]},
            { title: '寄存金额', key: 'depositAmount', width: '10%', type: FormTypes.inputNumber,statistics: true,
              validateRules: [{ required: false, message: '${title}不能为空' }]},
            { title: '当日行情价', key: 'daily', width: '10%', type: FormTypes.input,
              validateRules: [{ required: false, message: '${title}不能为空' }]}
          ]
        },
        confirmLoading: false,
        validatorRules:{
          type:{
              rules: [{
                required: true, message: '请输入业务类型'
              }]
          },
          storeName:{
            rules: [{
              required: true, message: '请输入门店名称'
            }]
          },
          source:{
            rules: [{
              required: true, message: '请输入渠道来源'
            }]
          },
          date:{
            rules: [{
              required: true, message: '请输入到期日期'
            }]
          },
          name:{
            rules: [{
              required: true, message: '请输入客户名称'
            }]
          },
          startTime:{
            rules: [{
              required: true, message: '请输入开单时间'
            }]
          },
          tel:{
            rules: [{
              required: true,type: 'number',message: '请输入正确格式的联系号码(11位)', trigger: 'blur',
               transform (value) {
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    if(value.length<11){
                      return false
                    }
                    return Number(value)
                  }
                }
            }]
          },
          idNumber:{
            rules: [{
              required: true,type: 'string', message: '请输入正确身份证号码', trigger: 'blur',
               transform (value) {
                  var moneyg = /^\d+X?$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    if(value.length<18){
                      return false
                    }
                    return value
                  }
                }
            }]
          },
          address:{
            rules: [{
              required: false, message: '请输入联系地址'
            }]
          },
          type:{
            rules: [{
              required: true, message: '请输入业务类型'
            }]
          },
          category:{
            rules: [{
              required: true, message: '请输入物品类别'
            }]
          },
          level:{
            rules: [{
              required: true, message: '请输入物品鉴定级别'
            }]
          },
          amount:{
            rules: [{
              required: true, message: '请输入数量', trigger: 'blur'
            }]
          },
          brandWeight:{
            rules: [{
              required: true, message: '请输入品牌,规格,重量'
            }]
          },
          depositAmount:{
            rules: [{
              required: true, message: '请输入正确的寄存金额（小数点保留两位）', type: 'number', trigger: 'blur',
               transform (value) {
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    return Number(value)
                  }
                }
            }]
          },
          daily:{
            rules: [{
              required: true, message: '请输入正确的当日行情价', type: 'number', trigger: 'blur',
               transform (value) {
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    return Number(value)
                  }
                }
            }]
          },
          recyclePrice:{
            rules: [{
              required: true, message: '请输入正确的回收单价', type: 'number', trigger: 'blur',
               transform (value) {
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    return Number(value)
                  }
                }
            }]
          },
          recycleTotal:{
            rules: [{
              required: true, message: '请输入正确的回收总价', type: 'number', trigger: 'blur',
               transform (value) {
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    return Number(value)
                  }
                }
            }]
          },
          deliveryPrice:{
            rules: [{
              // required: true,
               message: '请输入正确的出货价/还款金额', type: 'number', trigger: 'blur',
               transform (value) {
                  if(value == '' || value == undefined){
                    return ''
                  }
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    return Number(value)
                  }
                }
            }]
          },
          feedback:{
            rules: [{
              // required: true,
               message: '请输入行情收益反馈'
            }]
          },
          profit:{
            rules: [{
              message: '请输入收益'
            }]
          },
          rate:{
            rules: [{
              // required: true,
               message: '请输入寄存时长服务费率'
            }]
          },
          ope:{
            rules: [{
              required: true, message: '请输入业务员姓名'
            }]
          },
          endTime:{
            rules: [{
              // required: true,
               message: '请输入寄存到期时间记录/出货时间'
            }]
          },
          reminder:{
            rules: [{
              // required: true,
               message: '请输入到期提醒'
            }]
          },
          remark:{
            rules: [{
              // required: false,
               message: '请输入其他备注'
            }]
          },
          fileName:{
            rules: [{
              // required: true,
               message: '请上传业务图片'
            }]
          },
          imgName:{
            rules: [{
              // required: true,
               message: '请上传业务图片'
            }]
          }
        },
        url: {
          list: "/business/list",
          // add是新增的接口
          add: '/business/addBusinessAndItem'
        }
      }
    },
    created () {
      const token = Vue.ls.get(ACCESS_TOKEN);
      this.headers = {"X-Access-Token":token};
    },
    watch:{
      deposit(value){
        // 当寄存金额改变的时候，同时修改收益的取值
        if(this.rate.option[this.rate.index] instanceof Object){
          this.model.profit = (value * (this.rate.option[this.rate.index].rate / 100)).toFixed(2)
        }
      },
      model:{
        handler(value){
          if(this.rate.option[this.rate.index] instanceof Object && value.startTime !== ''){
            // 到期时间记录 = 开单时间 + 寄存时长
            let date = new Date(value.startTime)
            if(this.rate.option[this.rate.index].rate == 10){
            this.model.endTime = this.formDate(new Date(date.setMonth(date.getMonth() + 1)))
          }else{
            this.model.endTime = this.formDate(new Date(date.setDate(date.getDate() + this.rate.option[this.rate.index].date)))
          }
          }
          // 收益 等于 出货价 减去 回收总价 (不填写出货价,就不启用)
          // if(this.model.type == '回收'){
            // this.model.profit = this.model.deliveryPrice - this.model.recycleTotal
          // }
        },deep:true
      }
    },
    methods: {
      formDate(date){
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            const dateString = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            return dateString
         },
         // 如果业务类型是信用贷款，那么寄存金额将取身份证查询到的金额 的80% 
      ChangeCreditDepositAmount(){
        let c = (Number(this.credit.text) * 0.8).toFixed(2)
        this.$refs[this.refKeys[0]].rows.forEach(item => {
            this.$refs[this.refKeys[0]].setValues([{rowKey: item.id, values: {depositAmount:c}}])
        })
        this.$refs[this.refKeys[0]].recalcOneStatisticsColumn("depositAmount")
      },
      ChangeRate(value,event){
        this.rate.index = event.data.key
        if(this.rate.option[event.data.key] instanceof Object){
          // 收益 = 寄存金额 * 服务费率
          this.model.profit = (this.deposit * (this.rate.option[this.rate.index].rate / 100)).toFixed(2)
          this.rate.currentRate = this.rate.option[this.rate.index].rate
          // 到期时间记录 = 开单时间 + 寄存时长
          let date = new Date(this.model.startTime)
          if(this.rate.option[this.rate.index].rate == 10){
            this.model.endTime = this.formDate(new Date(date.setMonth(date.getMonth() + 1)))
          }else{
            this.model.endTime = this.formDate(new Date(date.setDate(date.getDate() + this.rate.option[this.rate.index].date)))
          }
        }else{
          // 清除收益 和 寄存到期时间记录
          this.model.profit = ''
          this.model.endTime = ''  
        }
      },
      getCredit(e){
        if(e.target.value.length >= 18){
          let params = {
            idNum:e.target.value
          }
          let that = this
          getCustomInfoByNum(params).then(e => {
            if(!(e.data instanceof Array) || e.data.length <= 0){
              that.credit.text = '0'
              that.credit.color = 'gray'
              that.credit.show = true
              that.isNoCredit = false
              if(that.model.type == '信用贷款')
                that.ChangeCreditDepositAmount()
              return
            }
            let { profit, credit } = e.data[0]
            that.credit.text = profit
            that.credit.color = 'green'
            that.credit.show = true
            if(profit < 0)
              that.credit.color = 'red'
            if(that.model.type == '信用贷款')
            that.ChangeCreditDepositAmount() 
            if(credit == '黑名单'){
              that.duration = null
              that.isNoCredit = true
              Modal.error({
                title:"系统提示",
                centered:true,
                content:"您输入的用户在黑名单内，请重新输入"
              })
              // notification.error({
              //   message:'系统提示',
              //   description:
              //   '您输入的用户在黑名单内，请重新输入',
              //   duration:that.duration
              // })
              // 这里开始禁用所有
              return
            }else{
              // 解除禁用
              that.isNoCredit = false
            }
          }).catch(e => {
            console.warn(e, 'error');
          })
        }else{
          this.credit.show = false
        }
      },
      onDeleted(event,target){
        // 若新增行没有表格了，就自动添加一行
        if((target.rows.length)  <= 0){
          let rowNum = this.addDefaultRowNum
          if (typeof rowNum !== 'number') {
            rowNum = 1
            console.warn('由于你没有在 data 中定义 addDefaultRowNum 或 addDefaultRowNum 不是数字，所以默认添加一条空数据，如果不想默认添加空数据，请将定义 addDefaultRowNum 为 0')
          }
          this.eachAllTable((item) => {
            item.add(rowNum)
          })
          if(this.model.type == '信用贷款'){
            let that = this
            setTimeout(() => {
                that.ChangeCreditDepositAmount()
            }, 0);
          }
        }
      },
      changeType(value){
        for (var i = 0; i <this.typeList.length; i++) {
          var oneSubject = this.typeList[i]
          if(value === oneSubject.name){
            // this.type = oneSubject.name
            let arr = oneSubject.categoryList
            let changeTypeColumns = () => {
              let clean_arr = () => {
                let len = this.materialTable.columns.length
                for(let i = 0; i < len; i ++){
                  this.materialTable.columns.pop()
                }
              }
              this.model.type = value
              if(value === "回收"){
                // 回收列
                // 删除寄存金额那一列
                clean_arr()

  // 回收默认显示（10天）[如果取消注释，则默认回收显示10天]------------------------------------------
                // this.rate.index = 1
                // this.model.rate = this.rateList[1]
                this.materialTable.columns.push(...this.columns.recycle)
              }else if(value === '信用贷款'){
                // 信用贷款列
                clean_arr()
                this.materialTable.columns.push(...this.columns.credit)
              }
              else{
                // 其他列
                clean_arr()
                this.materialTable.columns.push(...this.columns.other)
              }
            }
  // 回收默认显示（10天）[如果取消注释，则默认回收显示10天]------------------------------------------
            // if(value !== "回收"){
              this.rate.index = -1
              this.model.rate = ''
              this.model.endTime = ''
              this.model.recycleTotal = ''
              // 回收的时候，状态为程序中收益为0
              if(this.type == '回收'){
                  this.model.profit = 0
              }
            // }
            // 修改为空
            changeTypeColumns()
            this.materialTable.columns[0].options = []
                      console.log(arr,'arr');
            for(let i=0; i<arr.length; i++) {
              let depotInfo = {};
              depotInfo.value = arr[i].name  //注意-此处value必须为字符串格式
              depotInfo.text = arr[i].name
              depotInfo.title = arr[i].name
              depotInfo.levelList = arr[i].levelList
              this.materialTable.columns[0].options.push(depotInfo)
            }
            // 当type的值改变的时候，将其列表值都设置为空
            this.$refs[this.refKeys[0]].removeRows(this.$refs[this.refKeys[0]].rows.map(item => item.id))
            this.model.profit = ''
        }
        console.log(this.model, 'model');
        }        
      },
          //单元值改变一个字符就触发一次
    onValueChange(event) {
      const { type, row, column, value, target } = event
      switch(column.key) {
        case "type":
              if(event.column && event.column.options) {
                for (var i = 0; i <this.materialTable.columns[0].options.length; i++) {
                  var oneSubject = this.materialTable.columns[0].options[i]
                  if(value===oneSubject.name){
                    let arr = oneSubject.categoryList
                    // 修改为空
                    this.materialTable.columns[1].options = []
                    for(let i=0; i<arr.length; i++) {
                      let depotInfo = {};
                      depotInfo.value = arr[i].name  //注意-此处value必须为字符串格式
                      depotInfo.text = arr[i].name
                      depotInfo.title = arr[i].name
                      depotInfo.levelList = arr[i].levelList
                      this.materialTable.columns[1].options.push(depotInfo)
                    }
                    // 当type的值改变的时候，将其他的列表都设置为空
                  target.setValues([{rowKey: row.id, values: {category:'',level:''}}])
                  }
                }
            }
          break;
        case "category":
          for(let i = 0; i< this.materialTable.columns[0].options.length; i++){
            var oneSubject = this.materialTable.columns[0].options[i]
              if(value == oneSubject.value){
                    let arr = oneSubject.levelList
                    // 修改为空
                    this.materialTable.columns[1].options = []
                    for(let i=0; i<arr.length; i++) {
                      let depotInfo = {};
                      depotInfo.value = arr[i].name  //注意-此处value必须为字符串格式-
                      depotInfo.text = arr[i].name
                      depotInfo.title = arr[i].name
                      depotInfo.levelList = arr[i].levelList
                      this.materialTable.columns[1].options.push(depotInfo)
                    }
            }
            target.setValues([{rowKey: row.id, values: {level:''}}])
          }
          break;
          case "brandWeight":
          case "recyclePrice":  
            if(this.model.type !== '回收')
              return
          // 如果修改的不是回收，那么就直接退出
            let reg = /(((\d+)$)|((\d+)\.(\d+))g$|((\d+)\.(\d+))$|((\d+g)$))/g
            let result = row.brandWeight.match(reg)
            if(result == null){
              target.setValues([{rowKey: row.id, values: {recycleTotal: 0}}])
            }else{
              let index = result[0].search('g')
              let recyclePrice = row.recyclePrice
              let rs = ((index == -1 ? result[0] : result[0].substring(0,index)) * recyclePrice).toFixed(2)
              target.setValues([{rowKey: row.id, values: {recycleTotal: rs}}])
              this.$refs[this.refKeys[0]].recalcOneStatisticsColumn("recycleTotal")
            }
            // 收益 等于 出货价 减去 回收总价
            this.model.recycleTotal = target.statisticsColumns.recycleTotal
          break
          case "depositAmount":
            this.deposit = target.statisticsColumns.depositAmount;
            this.model.amountCount = this.deposit
          break
      }
    },
    parseInfoToObj(mInfo) {
        return {
          category: mInfo.category,
          level: mInfo.level,
          amount: 0,
          brandWeight: mInfo.brandWeight,
          depositAmount: mInfo.unit,
          daily: 0,
          recyclePrice: 0,
          recycleTotal: 0,
        }
      },
      init_rate(){
        this.rate.index = -1
        this.rate.currentRate = 0
        this.model.rate = ''
        this.model.profit = ''
        this.model.endTime = ''
      },
      add(){
        this.credit.show = false
        this.init_rate()
        this.form.resetFields()
        this.init_materialTable()
        this.visible = true
        let rowNum = this.addDefaultRowNum
        if (typeof rowNum !== 'number') {
          rowNum = 1
          console.warn('由于你没有在 data 中定义 addDefaultRowNum 或 addDefaultRowNum 不是数字，所以默认添加一条空数据，如果不想默认添加空数据，请将定义 addDefaultRowNum 为 0')
        }
        this.eachAllTable((item) => {
          item.add(rowNum)
        })        
        this.getBusinessList({})
        this.getSourceList({})
        this.getOperatorList({})
      },
      init_materialTable(){
        let len = this.materialTable.columns.length
        for(let i = 0; i < len; i ++){
          this.materialTable.columns.pop()
        }        
        this.materialTable.columns.push(...this.columns.other)
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let billMain = Object.assign(this.model, allValues.formValue)
        let detailArr = allValues.tablesValue[0].values
        if(this.model.id){
          billMain.id = this.model.id
        }
        return {
          info: JSON.stringify(billMain),
          rows: JSON.stringify(detailArr),
        }
      },
    }
      
  }
</script>
<style scoped>

</style>